package com.pearadmin.modules.sys.controller.work;

import com.github.pagehelper.PageInfo;
import com.pearadmin.modules.sys.domain.WorkOperateAnodeHistory;
import com.pearadmin.common.tools.string.Convert;
import com.pearadmin.common.web.base.BaseController;
import com.pearadmin.common.web.domain.request.PageDomain;
import com.pearadmin.common.web.domain.response.Result;
import com.pearadmin.common.web.domain.response.module.ResultTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.pearadmin.modules.sys.service.IWorkOperateAnodeHistoryService;

/**
 * 阳极在位历史记录Controller
 *
 * @author Mr.Ling
 * @date 2022-01-11
 */
@RestController
@RequestMapping("/anodeHistory/operateAnodeHistory")
public class WorkOperateAnodeHistoryController extends BaseController {

    private String prefix = "anodeHistory/operateAnodeHistory";

    @Autowired
    private IWorkOperateAnodeHistoryService workOperateAnodeHistoryService;

    @GetMapping("/main")
    @PreAuthorize("hasPermission('/anodeHistory/operateAnodeHistory/main','anodeHistory:operateAnodeHistory:main')")
    public ModelAndView main() {
        return jumpPage(prefix + "/main");
    }

    /**
     * 查询阳极在位历史记录列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/anodeHistory/operateAnodeHistory/data','anodeHistory:operateAnodeHistory:data')")
    public ResultTable list(@ModelAttribute WorkOperateAnodeHistory workOperateAnodeHistory, PageDomain pageDomain) {
        PageInfo<WorkOperateAnodeHistory> pageInfo = workOperateAnodeHistoryService.selectWorkOperateAnodeHistoryPage(workOperateAnodeHistory, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 新增阳极在位历史记录
     */
    @GetMapping("/add")
    @PreAuthorize("hasPermission('/anodeHistory/operateAnodeHistory/add','anodeHistory:operateAnodeHistory:add')")
    public ModelAndView add() {
        return jumpPage(prefix + "/add");
    }

    /**
     * 新增保存阳极在位历史记录
     */
    @ResponseBody
    @PostMapping("/save")
    @PreAuthorize("hasPermission('/anodeHistory/operateAnodeHistory/add','anodeHistory:operateAnodeHistory:add')")
    public Result save(@RequestBody WorkOperateAnodeHistory workOperateAnodeHistory) {
        return decide(workOperateAnodeHistoryService.insertWorkOperateAnodeHistory(workOperateAnodeHistory));
    }

    /**
     * 修改阳极在位历史记录
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/anodeHistory/operateAnodeHistory/edit','anodeHistory:operateAnodeHistory:edit')")
    public ModelAndView edit(String id, ModelMap mmap) {
        WorkOperateAnodeHistory workOperateAnodeHistory =workOperateAnodeHistoryService.selectWorkOperateAnodeHistoryById(id);
        mmap.put("workOperateAnodeHistory", workOperateAnodeHistory);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改保存阳极在位历史记录
     */
    @ResponseBody
    @PutMapping("/update")
    @PreAuthorize("hasPermission('/anodeHistory/operateAnodeHistory/edit','anodeHistory:operateAnodeHistory:edit')")
    public Result update(@RequestBody WorkOperateAnodeHistory workOperateAnodeHistory) {
        return decide(workOperateAnodeHistoryService.updateWorkOperateAnodeHistory(workOperateAnodeHistory));
    }

    /**
     * 删除阳极在位历史记录
     */
    @ResponseBody
    @DeleteMapping("/batchRemove")
    @PreAuthorize("hasPermission('/anodeHistory/operateAnodeHistory/remove','anodeHistory:operateAnodeHistory:remove')")
    public Result batchRemove(String ids) {
        return decide(workOperateAnodeHistoryService.deleteWorkOperateAnodeHistoryByIds(Convert.toStrArray(ids)));
    }

    /**
     * 删除
     */
    @ResponseBody
    @DeleteMapping("/remove/{id}")
    @PreAuthorize("hasPermission('/anodeHistory/operateAnodeHistory/remove','anodeHistory:operateAnodeHistory:remove')")
    public Result remove(@PathVariable("id") String id) {
        return decide(workOperateAnodeHistoryService.deleteWorkOperateAnodeHistoryById(id));
    }
}
